<?php


namespace App\Containers\AppSection\Questionnaire\Actions;


use App\Containers\AppSection\Log\Tasks\CreateLogTask;
use App\Containers\AppSection\Profile\Tasks\UpdateProfileTask;
use App\Containers\AppSection\Questionnaire\SubActions\UpdateResponseSubAction;
use App\Containers\AppSection\Questionnaire\UI\API\Requests\UpdateResponseRequest;
use App\Ship\Parents\Actions\Action;

class UpdateResponseAction extends Action
{
    public function run($id, UpdateResponseRequest $request)
    {
        $data = $request->sanitizeInput(['values']);

        app(UpdateResponseSubAction::class)->run($id, $data);

        //Смена статуса аккредитации
        if (!$request->profile()->hasAccreditationStatus('accreditation_returned'))
            app(UpdateProfileTask::class)
                ->run($request->profile()->id, [
                    'accreditation_status_key' => 'accreditation_not_accredited',
                    'accredited_at' => null
                ]);

        app(CreateLogTask::class)->run($request->profile()->id, 'Редактирование анкеты', 'profile');
    }
}
